<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>${sysName}</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${resRoot}/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${resRoot}/layui/admin/admin.css" media="all" />
	<link id="layuicss-layer" rel="stylesheet" href="${resRoot}/layui/css/modules/layer/default/layer.css" media="all">
	<script type="text/javascript" src="${resRoot}/ckeditor/ckeditor.js"></script>
	<script type="text/javascript" src="${resRoot}/ckfinder/ckfinder.js"></script>
</head>
<body>
<div class="layui-fluid">   
          <div class="layui-card">
          <div class="layui-form layui-card-header layuiadmin-card-header-auto"> 
 
<form class="layui-form" action="#" style="margin-top: 20px;margin-bottom:50px;" >
<input type="hidden" id="id" value="<#if databaseDTO??>${databaseDTO.id}<#else></#if>" >
  <div class="layui-form-item">
    <label class="layui-form-label">数据名称</label>
    <div class="layui-input-inline">
	      <input type="text" name="dbName" id="dbName" value="<#if databaseDTO?? && databaseDTO.dbName?? >${databaseDTO.dbName!}</#if>" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入数据连接url</div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">数据连接</label>
    <div class="layui-input-inline">
	      <input type="text" name="dbHost" id="dbHost" value="<#if databaseDTO?? && databaseDTO.dbHost?? >${databaseDTO.dbHost!}</#if>" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入数据连接url</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">驱动类</label>
    <div class="layui-input-inline">
	      <input type="text" name="dbDriverName" id="dbDriverName" value="<#if databaseDTO?? && databaseDTO.dbDriverName?? >${databaseDTO.dbDriverName! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入数据驱动</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">端口号</label>
    <div class="layui-input-inline">
	      <input type="text" name="dbPort" id="dbPort" value="<#if databaseDTO?? && databaseDTO.dbPort?? >${databaseDTO.dbPort! }<#else>3306</#if>" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入端口号</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-inline">
	      <input type="text" name="dbUserName" id="dbUserName" value="<#if databaseDTO?? && databaseDTO.dbUserName?? >${databaseDTO.dbUserName! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入用户名</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
	      <input type="text" name="dbPassword" id="dbPassword" value="<#if databaseDTO?? && databaseDTO.dbPassword?? >${databaseDTO.dbPassword! }</#if>" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请输入密码</div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">数据库类型</label>
    <div class="layui-input-inline">
    	<select name="dbType" id="dbType" >
    	<#list dictMap['db_type']?keys as key>
    	<option <#if databaseDTO?? && databaseDTO.dbType?? && databaseDTO.dbType==key ></#if> value="${key}" >${dictMap['db_type'][key]}</option>
    	</#list>
    	</select>
    </div>
    <div class="layui-form-mid layui-word-aux">请输入数据库类型</div>
  </div>
  

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" id="submitBtn"  lay-submit=""  type="button">立即提交</button>
      <button type="button" class="layui-btn layui-btn-primary" onclick="backList();" >返回</button>
    </div>
  </div>
</form>
</div>
  </div>
  </div>
<script src="${resRoot}/layui/layui.js" charset="utf-8"></script>
<script src="${resRoot}/js/jquery.min.js?v=2.1.4"></script>
<script type="text/javascript" src="${resRoot}/js/ajaxfileupload.js"></script>
<script>
function backList() {
	layer.closeAll("iframe");
    //刷新父页面
    parent.location.reload();
}

function removeImg(id) {
	layer.confirm('您是确认删除/查看该图片吗？', {
		  btn: ['确认','查看'] //按钮
		}, function(){
			$("#" + id).attr("src", "");
			layer.msg('已删除！');
		}, function(){
			window.open($("#" + id).attr("src"));
		  //layer.msg('已取消！');
		});
}
layui.use(['form', 'layedit', 'laydate', 'upload'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  var upload = layui.upload;

  
  
	
  
  //自定义验证规则
  form.verify({
    title: function(value){
      if(value.length == 0){
        return '参数不能为空';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
  
  
  
  $("#submitBtn").click(function(){
		var dbHost=$("#dbHost").val();
	  var id = $("#id").val();
		var dbDriverName=$("#dbDriverName").val();
		var dbPort=$("#dbPort").val();
		var dbUserName=$("#dbUserName").val();
		var dbPassword=$("#dbPassword").val();
		var dbType=$("#dbType").val();
		var dbName = $("#dbName").val();
		var flag = true;
		if(dbName=="" || dbName ==null || dbName =="undefined") {
			layer.alert("请输入数据库名称！");
		      flag = false;
		      return false;
		}
		if(dbHost=="" || dbHost ==null || dbHost =="undefined") {
			layer.alert("请输入数据连接url！");
		      flag = false;
		      return false;
		}
		if(dbDriverName=="" || dbDriverName ==null || dbDriverName =="undefined") {
			layer.alert("请输入数据驱动类！");
		      flag = false;
		      return false;
		}
		if(dbPort=="" || dbPort ==null || dbPort =="undefined") {
			layer.alert("请输入端口号！");
		      flag = false;
		      return false;
		}
		if(dbUserName=="" || dbUserName ==null || dbUserName =="undefined") {
			layer.alert("请输入用户名！");
		      flag = false;
		      return false;
		}
		if(dbPassword=="" || dbPassword ==null || dbPassword =="undefined") {
			layer.alert("请输入密码！");
		      flag = false;
		      return false;
		}
		if(dbType=="" || dbType ==null || dbType =="undefined") {
			layer.alert("请输入数据库类型！");
		      flag = false;
		      return false;
		}
		if(flag) {
			$.ajax({
				type : "post",
				url : "${base}/sys/database/save",
				data : {
					dbName : dbName,
					dbHost : dbHost,
					dbDriverName : dbDriverName,
					dbPort : dbPort,
					dbUserName : dbUserName,
					dbPassword : dbPassword,
					dbType : dbType,
					id : id					
					},
				dataType : "json",
				async : false,
				success : function(data) {
					if(data.message == 2) {
							layer.msg('请完善数据！');   
						} else if(data.message == 1) {
							layer.msg('保存成功！', {
							  icon: 1,
							  time: 2000 //2秒关闭（如果不配置，默认是3秒）
							}, function(){
								backList();
							});   
						} else {
							layer.msg('系统繁忙！'); 
						}
				}
			}); 
		}
	});
  
  
});

layui.use('upload', function(){
	  
});  
</script>
</body>
</html>